#conding = utf-8
import sys
sys.path.append("D:/seleniumpython")
from selenium import webdriver
from business.register_business import RegisterBusiness
import time
import unittest
import HTMLTestRunner
import os


class FristCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://my.caissa.com.cn/Registered/index")
        self.register_b = RegisterBusiness(self.driver)
        time.sleep(2)
    
    def tearDown(self):
        time.sleep(2)
        for method_name,error in self._outcome.errors:
            if error:
                case_name = self._testMethodName
                file_path = os.path.join(os.getcwd()+"/report/"+case_name+".png")
                self.driver.save_screenshot(file_path)
                
        self.driver.close()

    #执行电话号码错误
    def test_register_phone_error(self):
        phone_error = self.register_b.get_phone_error("021-52835638","1234","3456","qiao2012","qiao2012")
        #电话号码错误没有找到，就算注册成功了，但是case用例执行失败了
        return self.assertFalse(phone_error)
        # if phone_error ==True:
        #     print("注册成功了，此条case执行失败")
    
    #执行验证码错误
    def test_code_error(self):
        code_error = self.register_b.get_code_error("13916787584","1234","3456","qiao2012","qiao2012")
        return self.assertFalse(code_error)
        # if code_error ==True:
        #     print("注册成功了，此条case执行失败")

    #执行短信验证码错误
    def test_phone_code_error(self):
        phone_code_error = self.register_b.get_phone_code_error("13916787584","1234","3456","qiao2012","qiao2012")
        return self.assertFalse(phone_code_error)
        # if phone_code_error == True:
        #     print("注册成功了，此条case执行失败")

    #执行输入密码错误
    def test_password_error(self):
        password_error = self.register_b.get_password_error("13916787584","1234","3456","123456","123456")
        return self.assertFalse(password_error)
        # if password_error == True:
        #     print("注册成功了，此条case执行失败")

     #执行确认密码错误
    def test_confirm_password_error(self):
        confirm_password_error = self.register_b.get_confirm_password_error("13916787584","1234","3456","qiao2012","qiao2013")
        return self.assertFalse(confirm_password_error)
        # if confirm_password_error == True:
        #     print("注册成功了，此条case执行失败")

    #执行成功
    def test_register_success(self):
        success = self.register_b.user_base("13916787584","1234","3456","qiao2012","qiao2012")
        return self.assertFalse(success)

        # if self.register_b.test_register_success() == True:
        #     print("注册成功，此条case执行成功")


if __name__ == "__main__":
    fiel_path = os.path.join(os.getcwd()+"/report/"+"frist_case.html")
    f = open(fiel_path,'wb')
    suite = unittest.TestSuite()
    suite.addTest(FristCase("test_register_phone_error"))
    suite.addTest(FristCase("test_code_error"))
    suite.addTest(FristCase("test_password_error"))
    suite.addTest(FristCase("test_confirm_password_error"))
    suite.addTest(FristCase("test_register_success"))
    # unittest.TextTestRunner().run(suite)
    runder = HTMLTestRunner.HTMLTestRunner(stream=f,title="This is frist register",description="这是第一个注册case")
    runder.run(suite)


    
